package com.example.navigationdemo.part3

import android.os.Bundle
import android.text.TextUtils
import android.view.View
import android.widget.Toast
import androidx.navigation.fragment.findNavController
import com.example.navigationdemo.R
import com.example.navigationdemo.base.BaseFragment
import kotlinx.android.synthetic.main.fragment_arg_1.*
import kotlinx.android.synthetic.main.fragment_arg_1.view.*

class Arg1Fragment : BaseFragment() {
    override fun initView(rootView: View) {
        rootView.tv_to_fragment_with_arg.setOnClickListener {
            if (TextUtils.isEmpty(et_arg.text.toString())) {
                Toast.makeText(rootView.context, "参数不能为空", Toast.LENGTH_SHORT).show()
                return@setOnClickListener
            }
            var bundle = Bundle()
            bundle.putString("arg1", et_arg.text.toString())
            findNavController().navigate(R.id.to_fragment_2, bundle)
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.fragment_arg_1
    }
}